package com.huaxin.device.dto.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import com.huaxin.hxenum.base.BaseCodeEnum;

/**
 * 设备运行状态
 */
public enum EquipmentStatus implements BaseCodeEnum<String> {

    NORMAL("normal", "正常"),
    FAULT("fault", "故障"),
    MAINTENANCE("maintenance", "维保"),
    REPAIR("repair", "维修"),
    OFFLINE("offline", "离线");

    @EnumValue
    private final String code;
    private final String displayName;

    EquipmentStatus(String code, String displayName) {
        this.code = code;
        this.displayName = displayName;
    }

    @JsonValue
    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDisplayName() {
        return displayName;
    }

    public static EquipmentStatus of(String code) {
        for (EquipmentStatus status : EquipmentStatus.values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        return null;
    }

    public static boolean isValid(String code) {
        for (EquipmentStatus status : EquipmentStatus.values()) {
            if (status.getCode().equals(code)) {
                return true;
            }
        }
        return false;
    }
}
